<!-- 预约看房弹窗 -->
<template lang="html">
  <transition name="fade">
    <div id="dialog-wrap">
      <div class="dialog-box">
        <i class="icon icon-close" @click.stop="$emit('input', false)"></i>
        <p class="dialog-title">填写预约信息</p>
        <section class="tip">
          <icon warn type="warn"></icon>
          <ol>
            <li>线下看房注意人身安全，要结伴而行</li>
            <li>选择白天看房，避免晚上看房，避免不合理定金</li>
            <li>发现虚假房源、业主不合理要求等请及时举报</li>
          </ol>
        </section>
        <ul class="dialog-form">
          <li>
            <group>
              <x-input :show-clear="false"class="i__name" v-model="name" placeholder="请输入姓名" text-align="left" label-width="80px" title="姓名：" ></x-input>
            </group>
            <group>
              <i class="icon__trigle"></i>
              <datetime
                class="i__time"
                v-model="appointDate"
                placeholder="请选择看房时间"
                format="YYYY-MM-DD HH:mm"
                :start-date="startDate"
                title="看房时间：">
              </datetime>
            </group>
          </li>
          <!-- <li class="dialog-item">
            <p class="item-value">
              <label for="checkbox">
                <input type="checkbox" class="check-box" id="checkbox" v-model="isChecked">
                <span>同意现场看房服务协议</span>
              </label>
            </p>
          </li> -->
        </ul>
        <x-button type="primary" class="dialog-submit" @click.native="submit">提交</x-button>
      </div>
    </div>
  </transition>
</template>

<script>
import { XButton, Datetime } from 'vux'
import moment from 'moment'
export default {
  props: {
    createUserId: {
      type: String,
      required: true
    },
    houseId: {
      required: true
    },
    landlordId: {
      required: true
    }
  },
  components: {
    XButton,
    Datetime
  },
  data () {
    return {
      startDate: moment().add(1, 'days').format('YYYY-MM-DD'),
      isChecked: false,
      name: '', // 姓名
      appointDate: '' // 看房时间
    }
  },
  methods: {
    beforeSubmit () {
      if (this.name === '') {
        this.$vux.toast.text('请输入姓名')
        return false
      } else if (this.appointDate === '') {
        this.$vux.toast.text('请选择看房时间')
        return false
      }
      //  else if (this.isChecked === false) {
      //   this.$vux.toast.text('请勾选同意现场看房服务协议')
      //   return false
      // }
      return true
    },
    submit () {
      if (this.beforeSubmit()) {
        let data = {
          name: this.name, // 租客姓名
          createUserId: this.createUserId, // 租客id
          houseId: this.houseId, // 房源id
          appointDate: this.appointDate.split(' ')[0], // 预约日期
          appointTime: this.appointDate.split(' ')[1], // 预约时间
          landlordId: this.landlordId // 房东id
        }
        this.$axiosPosting(this.$api.addHouseAppointment, data).then(res => {
          if (res.code === '0000') {
            let _this = this
            this.$vux.confirm.show({
              title: '操作提示',
              content: '您的预约申请提交成功，可前往我的预约清单查看预约行程。',
              confirmText: '预约清单',
              cancelText: '继续逛逛',
              onConfirm () {
                _this.$router.push('/myReservationForRenter?status=1')
              },
              onCancel () {
                _this.$router.push('/rentList')
              }
            })
            // this.$router.push('/myReservationForRenter')
          } else {
            this.$vux.toast.text(res.msg)
          }
        })
      }
    }
  },
  created () {
    let userInfo = JSON.parse(window.localStorage.getItem('userInfo') || '{}')
    this.name = userInfo.trueName || ''
  }
}
</script>

<style lang="less" scoped>
@import "../../../styles/baseVar.less";
ul, li{
  list-style: none;
  margin: 0;
  padding: 0;
}
 #dialog-wrap{
   position: fixed;
   top: 0;
   width: 100%;
   height: 100%;
   z-index: 100;
   background: rgba(0, 0, 0, .3);
   .icon{
     display: inline-block;
   }
   .icon-close{
     position: absolute;
     top: 12px; /* 14/40 */
     right: 10px; /* 20/40 */
     width: 12px; /* 23/40 */
     height: 12px; /* 23/40 */
     background: url('../../../images/rent/dialog_close.png') center no-repeat;
     background-size: cover;
   }
   .dialog-box{
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 330px; /* 478/40 */
    background: #fff;
   }
   .dialog-title{
     font-size: 20px; /* 40/40 */
     color: #000;
     text-align: center;
     padding-top: 25px; /* 50/40 */
     line-height: 1;
   }
   .dialog-form{
     padding: 20px; /* 40/40 */
     line-height: 30px; /* 60/40 */
     font-size: 13px; /* 26/40 */
     .dialog-item{
       display: flex;
       margin-bottom: 7px; /* 15/40 */
       margin-top: 8px;
     }
     .check-box{
       display: inline-block;
       width: 15px;
       height: 15px;
       position: relative;
       border-radius: 3px;
       vertical-align: sub;
       background: #dcdcdc;
     }
     .checked::after{
       content: '';
       position: absolute;
       width: 5px;
       height: 15px;
       transform: rotate(40deg);
       bottom: 2px;
       right: 0;
       border: 2px solid transparent;
       border-right-color: @spinner-color;
       border-bottom-color: @spinner-color;
     }
   }
   .dialog-submit{
     position: absolute;
     bottom: 0;
   }
 }
</style>

<style lang="less">
  .dialog-form{
    .weui-cells{
      margin-top: 0;
      font-size: 16px;
      &:before{
        border-top: none;
      }

      .weui-cell__ft{
        padding-right: 0;
        font-size: .75rem;
        &:after{
          display: none;
        }
      }
    }
    .weui-cell{
      padding: 10px 0;
    }
  }
  #dialog-wrap {
    .weui_icon_warn {
      position: absolute;
      top: 14px;
      left: 6px;
      color: #ff8a00;
    }
    .weui-cells:after {
      border: none;
    }
    .i__name {
      text-align: left;
      input {
        text-align: left;
      }
      .weui-cell__bd {
        border: 1px solid #ccc;
        border-radius: 3px;
        padding: 3px 11px;
        box-sizing: border-box;
      }
      .weui-label {
        width: 80px;
        display: inline-block;
        text-align: right;
      }
    }
    .i__time {
      position: relative;
      .vux-datetime-value {
        border: 1px solid #ccc;
        border-radius: 3px;
        padding: 4px 11px;
        box-sizing: border-box;
        text-align: left;
        color: red;
      }
    }
    .icon__trigle {
      width: 0;
      height: 0;
      border-top: 10px solid #777;
      border-left: 10px solid transparent;
      transform: rotate(135deg);
      position: absolute;
      right: 5px;
      top: 17px;
    }
  }
</style>
<style lang="less" scoped>
.tip {
  margin-top: 0px;
  padding: 14px 20px 0 20px;
  position: relative;
}

 ol {
  background: white;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.8;
  li {
    list-style: none;
    list-style-position: outside;
  }
}
</style>
